﻿<?php

if(!defined('IN_PHPSCUP'))exit('hacking'); 
class NavApp extends BaseApp
{
    function index()
    {

		$TB_nav = &$this->_model('nav'); 	 
		
		$navdata = $TB_nav->show();
		foreach($navdata as $key => $value)
		{
		 unset($navdata[$key]['config']);				
         $navdata[$key]['config'] = @unserialize($value['config']);		
		}
				
        $this->assign('navdata',$navdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('nav_list.view.html');
    }

    function edit()
    {	
		$id = $_GET['id'];
		
	    $TB_alonepage = &$this->_model('alonepage'); 		
		$data = $TB_alonepage->show();	
        $this->assign('lw_data', $data['data']);
		
	 	$categorydata_prot = & $GLOBALS['SCup']->_get_category_data('prot'); 		
        $this->assign('categorydata_prot', $categorydata_prot);			
	 	$categorydata_new = & $GLOBALS['SCup']->_get_category_data('new'); 		
        $this->assign('categorydata_new', $categorydata_new);			
		
				
		$TB_nav = &$this->_model('nav'); 	 
		
		$navdata = $TB_nav->oneshow($id);
        $navdata['config'] = @unserialize($navdata['config']);	

	    $this->assign('navdata', $navdata);		
			
	    $this->assign('nav_lang', get_all_dirname(ROOT_PATH . '/languages'));	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('nav_edit.view.html');
    }

    function add()
    {	
	    $TB_alonepage = &$this->_model('alonepage'); 	 
		
		$data = $TB_alonepage->show();	
        $this->assign('lw_data', $data['data']);
	 	$categorydata_prot = & $GLOBALS['SCup']->_get_category_data('prot'); 		
        $this->assign('categorydata_prot', $categorydata_prot);			
	 	$categorydata_new = & $GLOBALS['SCup']->_get_category_data('new'); 		
        $this->assign('categorydata_new', $categorydata_new);				
	    $this->assign('nav_lang', get_all_dirname(ROOT_PATH . '/languages'));	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('nav_add.view.html');
    }


    function addpost()
    {

	     $data = $_POST['data'];
		 
         $data_config = $data['config'];
		 
		 unset($data['config']);
		 
		 $data['config'] = serialize($data_config);//@unserialize

		 $data['lang'] = trim($GLOBALS['Lang']->_lang_tp);		 
		 $data['scup'] = 'scup';
	 
		 $TB_nav = &$this->_model('nav'); 	 
		
		 $TB_nav->post($data);
		 
		 $this->write_cache();
		 $this->index();

    }


    function editpost()
    {

	     $data = $_POST['data'];

		 
		 $id = intval($data['id']);	 
		 
         $data_config = $data['config'];
		 
		 unset($data['config']);
		 
		 $data['config'] = serialize($data_config);//@unserialize		 
		 $data['lang'] = trim($GLOBALS['Lang']->_lang_tp);	
		 $data['scup'] = 'scup';
		 

		 $TB_nav = &$this->_model('nav'); 	 
		
		 $TB_nav->editaction($id,$data);
		 
		 $this->write_cache();
		 $this->index();
		 

    }

    function lsort()
    {
		 $data = array();
		 
	     $id = $_GET['id'];
		 $data['sort'] = $_GET['v'];
		 
		 $TB_nav = &$this->_model('nav'); 	 		
		 $TB_nav->editsort($id,$data); 
		 
		 $this->write_cache();		 
		 $this->index();			  

    }

    function lname()
    {
		 $data = array();
		 
	     $id = $_GET['id'];
		 $data['name'] = $_GET['v'];
		 
		 $TB_nav = &$this->_model('nav');  	 		
		 $TB_nav->editname($id,$data); 
		 $this->write_cache();		 
		 $this->index();			  

    }
	

    function del()
    {

	     $id = $_GET['id'];
		 $TB_nav = &$this->_model('nav'); 	 
			 
		 $TB_nav->del($id);	
		 	 
		 $this->write_cache();		 
		 $this->index();	  

    }




    function cache()
    {
         
		 $this->write_cache();		 
		 $this->index();		 


    }	

    function write_cache()
    {
         
		
		del_file(ROOT_PATH . '/data/nav/');
        get_dir(ROOT_PATH . '/data/nav/');	 		 
		$TB_nav = &$this->_model('nav'); 
					
		$navdata = $TB_nav->allshow();
		
        $nav = & $GLOBALS['SCup']->_get_nav();	
		
		foreach($navdata as $key => $value)
		{				
        $nav->set_file($value['type'],$value['lang_type']);
				
        $nav->_set_nav(array('name'=>$value['name'],'link'=>$value['link'],'whree'=>$value['whree'],'sort_order'=>$value['sort_order'],'config'=>@unserialize($value['config'])),'sort_order');		
		}

    }



  
}

?>